package top.ranzhang.controller.user;


import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.ranzhang.bean.dto.ChildToUserDTO;
import top.ranzhang.bean.dto.UserLoginDTO;
import top.ranzhang.bean.vo.UserLoginVO;
import top.ranzhang.bean.vo.UserToChildVO;
import top.ranzhang.common.result.Result;
import top.ranzhang.service.IChildService;
import top.ranzhang.service.IUserService;

/**
 * 客户端用户模块
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/user/user")
public class UserController {

    private final IUserService userService;
    private final IChildService childService;

    /**
     * 登录
     * @param userLoginDTO
     * @return
     */
    @RequestMapping("/login")
    public Result Login(@RequestBody UserLoginDTO userLoginDTO){
        log.info("用户登录:{}", userLoginDTO);
        UserLoginVO result = userService.login(userLoginDTO);
        return Result.success(result, "登录成功");
    }

    /**
     * 获取用户信息
     * @return
     */
    @GetMapping("/getUser")
    public Result GetUser(Integer id){
        log.info("根据id获取用户儿童:{}", id);
        UserToChildVO childToUserDTO = userService.getByUserId(id);
        return Result.success(childToUserDTO);
    }
}
